# encoding: utf-8

m2 = 1
M2 = 2
m3 = 3
M3 = 4
fourth = 5
tritone = 6
fifth = 7


import random


class Chord(object):
    def __init__(self, intervals, name, inversion=0):
        self.name = name
        self.intervals = intervals
        self.inversion = inversion
    
    def invert(self, n):
        import copy
        new_intervals = copy.copy(self.intervals)
        for j in range(n):
            new_intervals.append(12 - sum(new_intervals))
            new_intervals = new_intervals[1:]
        
        return Chord(new_intervals, self.name, self.inversion + n)
    
    def getInversion(self):
        return self
    
    def getStartingNote(self):
        return random.choice(range(50, 70))
        

class SeventhChord(Chord):
    def getInversion(self):
        if self.name == u"מוקטן קטן":
            return self
        
        #else
        x = random.choice([0,1,2,3])
        ret = self.invert(x)
        
        if (x == 1):
            ret.name += u" קווינט סקסט"
        elif (x == 2):
            ret.name += u" טרצ-קוורט"
        elif (x == 3):
            ret.name += u" סקונד"
        
        return ret

class QuartialFourNotes(Chord):
    def __init__(self, intervals, name):
        Chord.__init__(self, intervals, u"קוורטיאלי " + name + u" ארבעה צלילים")
    
    def getStartingNote(self):
        return random.choice(range(53, 67))
    
class QuartialFiveNotes(Chord):
    def __init__(self, intervals, name):
        Chord.__init__(self, intervals, u"קוורטיאלי " + name + u" חמישה צלילים")
    
    def getStartingNote(self):
        return random.choice(range(45, 62))


class QuintialFourNotes(Chord):
    def __init__(self, intervals, name):
        Chord.__init__(self, intervals, u"קווינטיאלי " + name + u" ארבעה צלילים")
    
    def getStartingNote(self):
        return random.choice(range(48, 60))
    
class QuintialFiveNotes(Chord):
    def __init__(self, intervals, name):
        Chord.__init__(self, intervals, u"קווינטיאלי " + name + u" חמישה צלילים")
    
    def getStartingNote(self):
        return random.choice(range(40, 57))



# triads
major = Chord([M3, m3], u"מז'ור")
minor = Chord([m3, M3], u"מינור")
dim = Chord([m3, m3], u"מוקטן")
aug = Chord([M3, M3], u"מוקטן")
triads = [major, minor, dim, aug]

seventh_chords = [
                  SeventhChord([M3, m3, m3], u"מז'ור קטן"),
                  SeventhChord([M3, m3, M3], u"מז'ור גדול"),
                  SeventhChord([M3, M3, m3], u"מוגדל גדול"),
                  SeventhChord([M3, M3, M2], u"מוגדל קטן"),
                  SeventhChord([m3, M3, m3], u"מינור קטן"),
                  SeventhChord([m3, M3, M3], u"מינור גדול"),
                  SeventhChord([m3, m3, fourth], u"מוקטן גדול"),
                  SeventhChord([m3, m3, M3], u"מוקטן קטן"),
                  SeventhChord([m3, m3, m3], u"מוקטן מוקטן")
                  ]


Quartials_4notes = [
                    QuartialFourNotes([fourth, fourth, fourth], u"זך"),
                    QuartialFourNotes([fourth, tritone, fourth], u"אמצעי"),
                    QuartialFourNotes([tritone, fourth, fourth], u"תחתון"),
                    QuartialFourNotes([fourth, fourth, tritone], u"עליון"),
                    QuartialFourNotes([tritone, fourth, tritone], u"דו צדדי"),
                    ]

Quartials_5notes = [
                    QuartialFiveNotes([fourth, fourth, fourth, fourth], u"זך"),
                    QuartialFiveNotes([tritone, fourth, fourth, fourth], u"תחתון"),
                    QuartialFiveNotes([fourth, tritone, fourth, fourth], u"אמצעי תחתון"),
                    QuartialFiveNotes([fourth, fourth, tritone, fourth], u"אמצעי עליון"),
                    QuartialFiveNotes([fourth, fourth, fourth, tritone], u"עליון"),
                    QuartialFiveNotes([fourth, tritone, fourth, tritone], u"עליון ואמצעי תחתון"),
                    QuartialFiveNotes([tritone, fourth, tritone, fourth], u"תחתון ואמצעי עליון"),
                    QuartialFiveNotes([tritone, fourth, fourth, tritone], u"דו צדדי"),
                    ]

Quintials_4notes = [
                    QuintialFourNotes([fifth, fifth, fifth], u"זך"),
                    QuintialFourNotes([fifth, tritone, fifth], u"אמצעי"),
                    QuintialFourNotes([tritone, fifth, fifth], u"תחתון"),
                    QuintialFourNotes([fifth, fifth, tritone], u"עליון"),
                    QuintialFourNotes([tritone, fifth, tritone], u"דו צדדי"),
                    ]

Quintials_5notes = [
                    QuintialFiveNotes([fifth, fifth, fifth, fifth], u"זך"),
                    QuintialFiveNotes([tritone, fifth, fifth, fifth], u"תחתון"),
                    QuintialFiveNotes([fifth, tritone, fifth, fifth], u"אמצעי תחתון"),
                    QuintialFiveNotes([fifth, fifth, tritone, fifth], u"אמצעי עליון"),
                    QuintialFiveNotes([fifth, fifth, fifth, tritone], u"עליון"),
                    QuintialFiveNotes([fifth, tritone, fifth, tritone], u"עליון ואמצעי תחתון"),
                    QuintialFiveNotes([tritone, fifth, tritone, fifth], u"תחתון ואמצעי עליון"),
                    QuintialFiveNotes([tritone, fifth, fifth, tritone], u"דו צדדי"),
                    ]


#everything = seventh_chords + Quartials_4notes + Quartials_5notes
everything = Quintials_4notes + Quartials_4notes

if __name__ == '__main__':
    print seventh_chords[1].invert(2).intervals